home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / ftn / varargs.z / varargs
Encoding:
Text File  |  2002-10-03  |  5.3 KB  |  119 lines

  1. VARARGS(3F)                                          Last changed: 12-23-98
  2.  
  3.  
  4. NNAAMMEE
  5.      vvaarraarrggss, aarrggmmnntt, ggeettaaddrr, nnuullllookk, xxeettaarrgg, rreettoouurr - allow variable
  6.      number of arguments in argument list
  7.  
  8. SSYYNNOOPPSSIISS
  9.      ssuubbrroouuttiinnee aarrggmmnntt((_n_a_r_g_s))
  10.      iinntteeggeerr**44 _n_a_r_g_s
  11.  
  12.      ssuubbrroouuttiinnee ggeettaaddrr(( _n,, _i_a_d_d_r))
  13.      iinntteeggeerr**44 _n,, _i_a_d_d_r
  14.  
  15.      iinntteeggeerr**44 ffuunnccttiioonn nnuullllookk(( _n,, _i_a_d_d_r ))
  16.      iinntteeggeerr**44 _n,, _i_a_d_d_r
  17.  
  18.      ssuubbrroouuttiinnee xxeettaarrgg(( _n,, _l_e_n,, _i_a_r_g))
  19.      iinntteeggeerr**44 _n,, _l_e_n
  20.      aannyyttyyppee _i_a_r_g
  21.  
  22.      ssuubbrroouuttiinnee rreettoouurr(( _n_a_r_g_s,, _l_e_n_1,, _v_a_l_1,, _l_e_n_2,, _v_a_l_2,, ......,, _l_e_n_n,, _v_a_l_n ))
  23.      iinntteeggeerr**44 _n_a_r_g_s,, _l_e_n_1,, _l_e_n_2,, ...... _l_e_n_n
  24.      aannyyttyyppee _v_a_l_1,, _v_a_l_2,, ...... _v_a_l_n
  25.  
  26. IIMMPPLLEEMMEENNTTAATTIIOONN
  27.      IRIX systems
  28.  
  29. DDEESSCCRRIIPPTTIIOONN
  30.      These utilities are used to provide FORTRAN 77 support for subroutines
  31.      with variable number of arguments.  In order to use these utilities,
  32.      all variable argument subroutines must be declared in each source file
  33.      before they are referenced or defined.   This is done by adding a
  34.      $$vvaarraarrggss compiler directive at the beginning of the source file, as
  35.      shown by this example:
  36.  
  37.           $$vvaarraarrggss _v_a_s_u_b_1 _v_a_s_u_b_2 _v_a_s_u_b_3
  38.  
  39.      _v_a_s_u_b_1, _v_a_s_u_b_2, and _v_a_s_u_b_3 are the names of the variable argument
  40.      subroutines which are referenced or defined in the current source
  41.      file.
  42.  
  43.      aarrggmmnntt returns the number of actual arguments in the integer variable
  44.      _n_a_r_g_s.  The default behavior is to count each character argument in
  45.      the actual argument list as two arguments because both the character
  46.      address and its length will be put on the argument stack.  The
  47.      --cchhaarraarrgg11 option can be used to count each character argument as only
  48.      one argument.
  49.  
  50.      ggeettaaddrr returns the address of the _nth argument in the variable _i_a_d_d_r.
  51.      This function has to be used to get the length of a character argument
  52.      because it is passed by value, not by reference, like other Fortran
  53.      arguments.
  54.  
  55.      nnuullllookk returns 0 if the address of the _nth argument is the same as the
  56.      address contained in the variable _i_a_d_d_r.
  57.  
  58.      xxeettaarrgg initializes _l_e_n bytes of _i_a_r_g with the value of the _nth
  59.      argument.
  60.  
  61.      rreettoouurr returns values to the calling program by setting _n_a_r_g_s actual
  62.      arguments using _l_e_n_1, _l_e_n_2, ..., _l_e_n_n bytes of the values stored in
  63.      the variables _v_a_l_1, _v_a_l_2,..., _v_a_l_n, respectively.
  64.  
  65.      In normal usage of variable argument subroutines, when the formal
  66.      argument list is specified using the maximum number of arguments the
  67.      subroutine can receive, the argument addresses and return values are
  68.      passed in the standard f77 convention.  The only utility needed in
  69.      this case is aarrggmmnntt to determine the number of actual arguments passed
  70.      to the variable argument subroutine.
  71.  
  72.      The other utilities are needed when there is no formal argument list
  73.      in the variable argument subroutine.  xxeettaarrgg is normally used to
  74.      initializes some local variables to the initial values of the actual
  75.      arguments.  rreettoouurr is then used to return the locally calculated
  76.      values back to the calling subroutine by setting the actual arguments
  77.      to the values of the local variables.
  78.  
  79. EEXXAAMMPPLLEESS
  80.      $varargs chsign
  81.      program tvararg
  82.      i = 1
  83.      j = -2
  84.      k = 3
  85.      call chsign( i, j, k, "fourth argument", "fifth" )
  86.      print *, i, j, k
  87.      end
  88.  
  89.      subroutine chsign()
  90. C    This subroutine changes the sign of all integer arguments passed to it
  91. C    and prints the value of all character arguments.  It assumes that
  92. C    there are at most three integer arguments, followed by the character
  93. C    arguments.  The way this subroutine is written it has to be compiled
  94. C    with the -chararg1 option since it assumes that the lengths of the
  95. C    character arguments can be obtained by using GETADR(NARGS+I) where
  96. C    NARGS is the number of arguments returned by ARGMNT().
  97.      integer*4 val(3)
  98.      pointer (stradr, str)
  99.      character*(*) str
  100.  
  101.      call argmnt( nargs )
  102.      print *, "Number of arguments = ", nargs
  103.      j = min(3,nargs)
  104.      do 10 i=1,j
  105.          call xetarg( i, 4, val(i) )
  106. 10   val(i) = - val(i)
  107. C    Get the address and the length of the character arguments
  108.         do 100 i=j+1, nargs
  109.             call getadr( i, stradr )
  110.             call getadr( nargs+i-j, lenstr )
  111.             write (*,*) str(1:lenstr)
  112. 100     continue
  113.  
  114.      call retour(j,4,val(1),4,val(2),4,val(3))
  115.      end
  116.  
  117. SSEEEE AALLSSOO
  118.      This man page is available only online.
  119.